package question3;

import java.util.ArrayList;
import java.util.List;

public class Subject {
    private String name;
    private Department department; // 所属系
    private List<Instructor> instructors = new ArrayList<>();
    private List<Student> students = new ArrayList<>();

    public Subject(String name) {
        this.name = name;
    }

    // 设置所属系
    public void setDepartment(Department department) {
        this.department = department;
        department.addSubject(this); // 反向关联系
    }

    // 添加授课教师
    public void addInstructor(Instructor instructor) {
        instructors.add(instructor);
        instructor.addTaughtSubject(this);  // 反向关联教师
    }

    // 添加选修学生
    public void addStudent(Student student) {
        students.add(student);
        student.addSubject(this);   // 反向关联学生
    }
}
